package com.custom.action.core;

import com.custom.jdbc.configuration.DbDataSource;
import com.custom.jdbc.configuration.DbGlobalConfig;
import com.custom.jdbc.session.JdbcSqlSessionFactory;
import lombok.Getter;

/**
 * @author XiaoBai
 * @since 2024/4/18 11:24
 */
@Getter
public class BaseOpHandler {

    protected final SqlExecutor sqlExecutor;
    private final DbDataSource dbDataSource;
    private final DbGlobalConfig globalConfig;

    public BaseOpHandler(DbDataSource dbDataSource, DbGlobalConfig globalConfig) {
        this.dbDataSource = dbDataSource;
        this.globalConfig = globalConfig;
        sqlExecutor = new JdbcAction(dbDataSource, globalConfig);
    }

    public BaseOpHandler(JdbcSqlSessionFactory sqlSessionFactory) {
        this.dbDataSource = sqlSessionFactory.getDbDataSource();
        this.globalConfig = sqlSessionFactory.getGlobalConfig();
        sqlExecutor = new JdbcAction(sqlSessionFactory);
    }

}
